<template>
 <div>
 <el-table
        :data="rulelist"
        style="width: 100%;margin-bottom: 20px;"
        row-key="id"
        border
        default-expand-all
        :tree-props="{children: 'children'}"
      >
        <el-table-column prop="id" label="编号"></el-table-column>
        <el-table-column prop="rolename" label="角色名称"></el-table-column>

        <el-table-column label="状态">
          <template slot-scope="item">
            <div>
              <el-tag v-if="item.row.status==1" type="success">启用</el-tag>
              <el-tag v-else type="danger">禁用</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="300px">
          <template slot-scope="item">
            <el-button type="primary" @click="edit(item.row.id)" icon="el-icon-edit" circle></el-button>
            <el-button type="danger" @click="del(item.row.id)" icon="el-icon-delete" circle></el-button>
            <el-button type="success" icon="el-icon-check" circle></el-button>
            <el-button icon="el-icon-search" circle></el-button>
          </template>
        </el-table-column>
      </el-table>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { roleDel } from "../../util/request/api";
export default {
  data() {
    return {
      info: {
        isShow: false,
        isAdd: true
      }
    };
  },
  computed: {
    ...mapGetters({
      rulelist: "role/getRoleList"
    })
  },
  mounted() {
    //组件一加载就调用这个角色列表
    this.getRoleList();
  },
  methods: {
    ...mapActions({
      getRoleList: "role/getRoleAction"
    }),
    show() {
      this.info.isShow = true;
    },
    cancel(e) {
      this.info.isShow = false;
    },
    del(id) {
      this.$confirm("你确定要删除这条数据吗？？？？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          //调用删除接口
          roleDel({
            id
          }).then(res => {
            if (res.code == 200) {
              console.log(1111);

              this.$message.success(res.msg);
              //重新获取一下列表
              this.getRoleList();
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    edit(id) {
      this.$emit("edit", id);
    }
  },
};
</script>

<style scoped>
.el-main {
  height: 85vh;
  background: #ccc;
}
.title-p {
  width: 279px;
  font-size: 12px;
  margin: 0;
}
</style>
